package de.mobizcorp.DWRESTServer.services

import grails.test.spock.IntegrationSpec

import org.codehaus.groovy.grails.io.support.ClassPathResource

import spock.lang.*
import dw.catalog.Catalog
import dw.catalog.Category

/**
 * Integration test for the Demandware importer service
 */
class DemandwareImporterServiceSpec extends IntegrationSpec {
	DemandwareImporterService demandwareImporterService
	File catalogFile = new ClassPathResource("resources/catalog.xml").getFile()
	
    def setup() {
    }

    def cleanup() {
    }

	/**
	 * Check whenever the catalog import works and produces correct results
	 */
    void "test for importCatalog"() {
		when:
			demandwareImporterService.importCatalog(catalogFile)
			
		then:
			def catalog = Catalog.find("FROM Catalog AS c WHERE c.ID = ?", "BrooksBrothers_Site_US")
			
			assert catalog
			assert catalog.ID == "BrooksBrothers_Site_US"
    }
	
	void "test for categoryImport"() {
		when:
			demandwareImporterService.importCategories(catalogFile)
			
		then:
			def category = Category.find("FROM Category AS c WHERE c.ID = ?", "men")

			assert category
			assert category.ID == "men"
	}
}
